<!--
    金融产品信息
    参数：对象类型
    Obj: {
                contractNo: 合同号,
                roleType: 角色类型,（枚举类型：经销商:SP ）
            }
-->

<style scoped="scoped">
    /* @import "../../../styles/common/basic-info.css"; */
</style>
<template>
    <div class="basis-info" style="width: 100%;">
        <Form ref="formData" :model="formData" :rules="formRules" :label-width="100">
            <Row>
                <Col :xs="24" :md="12" :xl="6">
                    <FormItem label="金融产品名称">
                        <Input type="text" v-model="formData.basicMainInfo.productName" disabled/>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :xl="6">
                    <FormItem label="合同金额">
                        <RuiNumber v-model="formData.basicFinancialAgreement.contractAmt" type="currency" disabled/>
                    </FormItem>
                </Col>
                <Col v-if="type !== 'insurance'" :xs="24" :md="12" :xl="6">
                    <FormItem label="首付金额">
                        <RuiNumber type="currency" v-model="formData.basicFinancialAgreement.downPayAmt" :precision="2" disabled/>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :xl="6">
                    <FormItem label="贷款金额">
                        <RuiNumber type="currency" :precision="2" v-model="formData.basicFinancialAgreement.loanAmt" disabled/>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :xl="6">
                    <FormItem label="贷款期数">
                        <Input type="text" v-model="formData.basicFinancialAgreement.loanTerm" disabled/>
                    </FormItem>
                </Col>
                <Col v-show="type !== 'insurance'" :xs="24" :md="12" :xl="6">
                    <FormItem label="月供金额" v-if="!this.Obj.roleType">
                        <RuiNumber type="currency" v-model="formData.basicFinancialAgreement.monthPayAmt" disabled/>
                    </FormItem>
                </Col>
                <Col v-show="type !== 'insurance'" :xs="24" :md="12" :xl="6">
                    <FormItem label="客户利率" v-if="!this.Obj.roleType">
                        <InputNumber
                            disabled
                            :max="100"
                            v-model="formData.basicFinancialAgreement.custRate"
                            :formatter="value => `${value}%`"
                            :parser="value => value.replace('%', '')"></InputNumber>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :xl="6">
                    <FormItem label="已还期数" v-if="!this.Obj.roleType">
                        <Input type="text" v-model="formData.repaidTermNo" disabled/>
                    </FormItem>
                </Col>
                <Col v-show="type !== 'insurance'" :xs="24" :md="12" :xl="6">
                    <FormItem label="未还期数" v-if="!this.Obj.roleType">
                        <Input type="text" v-model="formData.notPaidTermNo" disabled/>
                    </FormItem>
                </Col>
                <Col v-show="type !== 'insurance'" :xs="24" :md="12" :xl="6">
                    <FormItem label="放款金额">
                        <RuiNumber type="currency" v-model="formData.basicPaymentPool.paymentAmt" disabled/>
                    </FormItem>
                </Col>
                <Col v-show="type !== 'insurance'" :xs="24" :md="12" :xl="6">
                    <FormItem label="放款状态">
                        <Select v-model="formData.basicPaymentPool.paymentStatus" disabled>
                            <Option v-for="item in dataDic.creditStatus" :value="item.value"
                                    :key="item.value" :label="item.title">
                                {{ item.title }}
                            </Option>
                        </Select>
                    </FormItem>
                </Col>
            </Row>
        </Form>
    </div>
</template>
<script>
    import {
        getBasicInfo,
        getFormData,
    } from "_p/basic/api/contract/common/finance-info/finance-info";
    import {deepClone} from "@/libs/utils/ObjectClone";
    import {getByTypes} from "_p/basic/api/admin/datadic";
    import {channelType} from "_p/basic/api/contract/channel-type/channel-type";

    export default {
        props: {
            //对象参数包含：合同号码、角色类型
            Obj: {
                type: Object,
                required: true
            },
            type: {
                type: String,
            }
        },
        data() {
            return {
                dataDic: {},
                formData: {
                    basicPaymentPool: {},
                    basicMainInfo: {},
                    basicFinancialAgreement: {},
                    repaidTermNo: "",
                    notPaidTermNo: ""
                },
                formRules: {}
            };
        },
        mounted() {
            this.init();
        },
        methods: {
            init() {
                this.getBasicInfo();
                this.getByDic();
                this.getFormData();
            },
            getByDic() {
                let arr = ["creditStatus"];
                getByTypes(arr).then(res => {
                    if (res.code === "0000") {
                        this.dataDic = deepClone(res.data);
                    }
                });
            },
            getBasicInfo() {
                if (!this.Obj.contractNo) return;
                getBasicInfo(this.Obj.contractNo, channelType(this.$route.meta.params)).then(res => {
                    if (res.code === "0000" && res.data) {
                        this.formData.basicMainInfo.productName = res.data.productName;
                        this.formData.basicFinancialAgreement = Object.assign({}, this.formData.basicFinancialAgreement, res.data);
                        this.formData.basicPaymentPool = Object.assign({}, this.formData.basicPaymentPool, res.data);
                    }
                });
            },
            getFormData() {
                if (!this.Obj.contractNo) return;
                getFormData(this.Obj.contractNo, channelType(this.$route.meta.params)).then(res => {
                    if (res.code === "0000" && res.data) {
                        this.formData.basicFinancialAgreement = Object.assign({}, this.formData.basicFinancialAgreement, res.data);
                        if (res.data) {
                            this.formData.repaidTermNo = res.data.paidTerm;
                            this.formData.notPaidTermNo = res.data.unpaidTerm + res.data.overdueTerm;
                        }
                    }
                });
            },
        }
    };
</script>
<style scoped>
    .basis-info >>> .ivu-input[disabled] {
        color: #000000;
    }

    .basis-info >>> .ivu-select-disabled .ivu-select-selected-value {
        color: #515a6e;
    }

    .basis-info >>> .ivu-input-number-input[disabled] {
        color: black;
    }
</style>
